package org.lemma.number;

import static org.lemma.number.Natural.ZERO;
import javax.annotation.Author;
import javax.annotation.Copyright;
import javax.annotation.Version;

/**
 * <p>
 * A <dfn>Real Number</dfn> is a representation of a continuous quantity that can be
 * expressed by a decimal representation.
 * </p>
 * <p>
 * Given a real number, <dfn>r = 1234.56789....</dfn>, the integer part of <i>r</i>
 * is <dfn>1234</dfn> and its fractional part is <dfn>56789...</dfn>
 * </p>
 * <div class="references">
 *  <cite>
 *  "Real number." <i>Wikipedia, The Free Encyclopedia</i>.
 *  17 Dec 2007, 14:27 UTC. Wikimedia Foundation, Inc.  4 Jan 2008
 *  <a href="http://en.wikipedia.org/w/index.php?title=Real_number&amp;oldid=178505552">
 *  http://en.wikipedia.org/w/index.php?title=Real_number&amp;oldid=178505552</a>
 *  </cite>
 * </div>
 *
 * @author Chris Beatty [christopher.beatty@gmail.com]
 * @version 1.0.0
 */
@Version (
    major="1", minor="0", patch="0", 
    date="Jun 16, 2008 2:06:23 PM",
    authors = {
        @Author (name="Chris Beatty", email="christopher.beatty@gmail.com")
    }
) @Copyright 
public abstract class Real extends Complex {
    
    /**
     * Default Class Constructor
     * Creates and initializes a new instance of {@code Real}
     */
    protected Real() {
        super(ZERO, ZERO);
    }
    
    /**
     * {@inheritDoc}
     * 
     * This method will always return a reference to this object itself
     * 
     * @return {@inheritDoc}
     */    
    @Override
    public Real realPart() {
        return this;
    }      
    
    /**
     * {@inheritDoc}
     * 
     * This method will always return zero, meaning there is no imaginary part
     * 
     * @return {@inheritDoc}
     */
    @Override
    public Real imaginaryPart() {
        return ZERO;
    }
    
    /**
     * The integer part (i.e., part before the decimal point) for this {@code Real} number
     * 
     * @return An {@link Integer}
     */
    public abstract Integer integerPart();
    
    /**
     * The fractional part (i.e., part after the decimal point) for this {@code Real} number
     * 
     * @return An {@link Integer}
     */    
    public abstract Integer fractionalPart();

    /**
     * {@inheritDoc} 
     * 
     * @return {@inheritDoc}
     */
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        if(this.sign() == Sign.Negative) {
            sb.append(this.sign().toString());
        }
        sb.append(this.integerPart().magnitude());
        sb.append('.');
        sb.append(this.fractionalPart().magnitude());
        return sb.toString();
    }

}
